-- 男巫小屋建筑

function initGargamelSlime(self, buildingInfo, dbase, pos)
    if type(dbase) ~= "table" or type(dbase["need_property"]) ~= "number" then
        -- 没要求，配置错误
        error("获取不到男巫冈布奥物品配置！");
        return;
    end

    -- 雇佣男巫
    local function okFun()
        -- 金币足够否
        local bonusArgs = SlimeEventM.query(101, "bonus_args")
        local cost = bonusArgs["cost"][1];
        if cost[1] ~= 2 or cost[2] ~= "money" then
            -- 配置错误
            error("男巫冈布奥扣除配置错误！");
            return;
        end

        -- 判断玩家金钱是否足够
        if ME.user.dbase:query(cost[2], 0) < cost[3] then
            -- 关闭建筑界面
             UIMgr.getCurrentScene():removeFormByName("UIBuildingView2");
            -- 显示商城购买金币界面
            showBuyMoneyTip();
            return;
        end

        -- 尝试尝试触发
        DungeonActionM.go("slime_event", pos, 101);

        -- 建筑消失
        playBuildingDisappear(self);
    end

    -- 购买碎片
    local function okFun2()
        -- 金币足够否
        local bonusArgs = SlimeEventM.query(102, "bonus_args")
        local cost = bonusArgs["cost"][1];
        if cost[1] ~= 2 or cost[2] ~= "money" then
            -- 配置错误
            error("男巫冈布奥扣除配置错误！");
            return;
        end

        -- 判断玩家金钱是否足够
        if ME.user.dbase:query(cost[2], 0) < cost[3] then
            -- 关闭建筑界面
             UIMgr.getCurrentScene():removeFormByName("UIBuildingView2");
            -- 显示商城购买金币界面
            showBuyMoneyTip();
            return;
        end

        -- 尝试尝试触发
        DungeonActionM.go("slime_event", pos, 102);

        -- 建筑消失
        playBuildingDisappear(self);
    end

    local petId = SlimeEventM.query(101, "dbase")["pet_id"];
    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 格子失效了
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            if EquipM.isEquiped(dbase["need_property"]) then
                -- 装备男巫法袍
                -- 有男巫,显示购买碎片
                if not petId then
                    error("SLIME_EVENT_101 (pet_id)没有配置！");
                    return;
                end

                if PetM.getMyPet(petId) then
                    self:openBuildingView2(okFun2, nil, getLocStr("btn_text_buy"), buildingInfo["view_text2"],
                        getLocStr("gargamel_slime_dialog"), nil, true);
                else
                    -- 没有男巫，显示雇佣男巫
                    self:openBuildingView2(okFun, nil, buildingInfo["view_text"], buildingInfo["view_text2"],
                        buildingInfo["dialog1"], nil, true);
                end
            else
                -- 没装备
                self:openBuildingView(nil, 0, buildingInfo["dialog2"], buildingInfo["view_text2"], nil, nil, nil, true);
            end
            AudioM.playFx("dup_shop");
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
    self.icon:addTouchEventListener(onClicked);
end
